package io.ydjs.api.app.auth.controller;


import io.ydjs.api.app.auth.request.PasswordLoginRequest;
import io.ydjs.api.app.auth.request.SmsLoginRequest;
import io.ydjs.api.app.auth.request.WxLoginRequest;
import io.ydjs.api.app.auth.response.LoginResponse;
import io.ydjs.api.app.auth.service.AppAuthService;
import io.ydjs.common.api.Result;
import io.ydjs.common.utils.ValidatorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户登录授权Api
 */
@RestController
@RequestMapping("/app/auth")
@Api(tags = "用户登录授权Api")
public class AppAuthController {

    private final AppAuthService appAuthService;

    public AppAuthController(AppAuthService appAuthService) {
        this.appAuthService = appAuthService;
    }

    /**
     * 微信小程序登录
     * @param request 登录请求
     * @return 登录结果
     */
    @PostMapping("/miniWxLogin")
    @ApiOperation("微信小程序登录")
    public Result<LoginResponse> miniWxLogin(@RequestBody WxLoginRequest request){

        ValidatorUtils.validateEntity(request);
        LoginResponse loginResponse = appAuthService.miniWxLogin(request);

        return new Result<LoginResponse>().ok(loginResponse);
    }

    /**
     * 手机验证码登录
     * @param request 登录请求
     * @return 登录结果
     */
    @PostMapping("/smsLogin")
    @ApiOperation("手机验证码登录")
    public Result<LoginResponse> smsLogin(@RequestBody SmsLoginRequest request){

        LoginResponse loginResponse = appAuthService.smsLogin(request);

        return new Result<LoginResponse>().ok(loginResponse);
    }

    /**
     * 账号密码登录
     * @param request 登录请求
     * @return 登录结果
     */
    @PostMapping("/password")
    @ApiOperation("账号密码登录")
    public Result<LoginResponse> smsLogin(@RequestBody PasswordLoginRequest request){

        LoginResponse loginResponse = appAuthService.passwordLogin(request);

        return new Result<LoginResponse>().ok(loginResponse);
    }


}
